#!/usr/bin/python
#
# Program to send GSMTAP packets with DL-MAP's to Wireshark.
# Reads raw DL-MAP bits from stdin, one line per DL-MAP.
#
# Example:
#   cat dl-maps.txt | ./gsmtap_dlmap_send.py
#
from socket import socket, AF_INET, SOCK_DGRAM
import sys
import binascii

def send_gsmtap_pcket(header_hex, payload_hex):
  data = header_hex + payload_hex
  packet = binascii.a2b_hex(data)
  
  port = 4729
  hostname = '127.0.0.1'
  udp = socket(AF_INET,SOCK_DGRAM)
  udp.sendto(packet, (hostname, port))

header_hex ='01040701000101010000000113010100'
#dlmap_bin = '110100000101010000000100101010100011100101011001000001010000001000000001000111010000010111111111001000000010001010010000000001110000000000000100011100101111010000001111000101000000101100101000101000000000000011100111000110010000000000001011000000000100100011110000001100100100001000001101000010001110111010001100100000000001010001000000000000000111111000011001001000000110000110000000011111100001100011101000011000100000000000000101000000000000000001011000011110000001001011111111111111110000000000000001100000001100101010001111111111111111101110000000001100000000010000100011001011111111111111111110000001000100011000101011000000010000110110111010000100000100001011010111'

for dlmap_bin in sys.stdin:
  dlmap_hex = "%x" % int(dlmap_bin,2)
  send_gsmtap_pcket(header_hex, dlmap_hex)

